<template>
  <customDrawer
    title="打印标签"
    :hideConfirm="true"
    :footer="false"
    attach="body" placement="right"
    ref="customDrawerSnList">
    <template #content>
      <data-view
        ref="dataView"
        propViewKey="delivery_item_sns_print"
        :propIsTdesign="true"
        :propAutoFetchData="false"
        @extra-button-click="handleExtraButton"
      />
    </template>
  </customDrawer>
</template>

<script>
export default {
  help: '标签-列表',
  data() {
    return {
      deliveryId: null
    }
  },
  computed: {
  },
  methods: {
    getWrapper() {
      let wrapper = this.$newWrapper()
      if (this.strings.isNotBlank(this.deliveryId)) {
        wrapper.eq('deliveryId', this.deliveryId)
      }
      return wrapper
    },
    loadDtl() {
      this.$refs.dataView.setQueryWrapper(this.getWrapper())
    },
    instDrawer() {
      return this.$refs.customDrawerSnList
    },
    instDv() {
      return this.$refs.dataView
    },
    show(deliveryId) {
      this.deliveryId = deliveryId
      this.instDrawer().show()
      this.loadDtl()
    },
    hide() {
      this.instDrawer().hide()
    },
    //按钮事件
    handleExtraButton(para) {
      let buttonKey = para.button.key
      switch (buttonKey){
        case 'printAll': { //打印全部
          this.utilVue.loadShow(true)
          const params = {
            queryString: this.utils.json2str(this.getWrapper().queryConditions)
          }
          this.$ajax.get('/order/delivery_item_sns/listForPrint', {params}).then((resp) => {
            this.utilVue.loadHide()
            if (resp.code == 0) {
              if (!resp.data || resp.data.length == 0) {
                this.utilMessage.warning('没有可打印的标签，请刷新重试')
                return
              }
              let param = {
                rows: resp.data
              }
              global.utilPrint.openLabel(param)
            }
          })
          break
        }
        case 'printSelect': { //打印所选
          let rows = this.instDv().$refs.tbMain.getCheckboxRecords()
          if (rows.length == 0 ){
            this.utilMessage.warning('请选择需要打印的标签')
            return
          }
          let param = {
            rows: rows
          }
          global.utilPrint.openLabel(param)
          break
        }
        case 'close': { //关闭
          this.hide()
          break
        }

      }
    }
  }
}
</script>
